#pragma once
#ifndef VISUALISATION_H
#define VISUALISATION_H

//window include
#include <windows.h>
#define WIN32_LEAN_AND_MEAN
#define VC_EXTRALEAN

//directx include
#include <d3dx9.h>

//other include
#include <vector>
using namespace std;

//forward declarations
class CGfxEntity;
class CCamera;
//class CGfxEntityTerrain;

class CVisualisation
{
private:
	//singleton variable
	static CVisualisation* instance;

	//window variables
	HWND m_hWnd;
	int m_width;
	int m_height;

	//graphic variables
	LPDIRECT3D9 m_d3dObject;
	LPDIRECT3DDEVICE9 m_d3dDevice;
	D3DXMATRIX worldMatrix;
	D3DXMATRIX viewMatrix;
	D3DXMATRIX projMatrix;

	CCamera* m_camera;

	//container 
	vector<CGfxEntity*> m_vectorGfxEntity;
	vector<LPDIRECT3DTEXTURE9> m_vectorTexture;
	bool m_modeWireframe;

	//font variable
	LPD3DXFONT m_font;

	//sprite variable
	LPD3DXSPRITE m_sprite;

public:
	//singleton function
	static CVisualisation* getInstance(void);
	void close();

	//component functions
	bool createWindow(int width, int height, const WNDCLASSEX* windowClass, HINSTANCE hInstance, int nCmdShow);
	bool initDirectX();

	//create entities
	bool loadModel(int* indexEntity, string adressModel);
	bool loadSkyBox(int* indexEntity, string adressModel);
	bool loadTerrain(int* indexEntity, int numCellsWide, int numCellsHigh, D3DXVECTOR3 minBound, D3DXVECTOR3 maxBound);

	//load font
	bool createFont();

	//load texture
	bool loadTexture(int* indexEntity, string addressTexture);

	void setWireframeMode(bool set);
	void createDirectionalLight(D3DXVECTOR3* direction, DWORD index);

	//gettors
	HWND getWindowHandle(void) const;
	LPDIRECT3DDEVICE9 getDevice() const; //temporaire
	CCamera* getCamera() const;
	D3DXVECTOR3 getMinBoundTerrain(int indexTerrain)const;
	D3DXVECTOR3 getMaxBoundTerrain(int indexTerrain)const;
	float getCellWidthTerrain(int indexTerrain)const;
	float getCellHeightTerrain(int indexTerrain)const;
	int getNumCellWide(int indexTerrain)const;
	int getNumCellHigh(int indexTerrain)const;
	D3DXVECTOR3 getVertexTerrain(int indexTerrain, int indexVertex)const;
	LPD3DXMESH getMesh(int index)const;
	bool getModeWireframe()const;
	int getWindowWidth()const;
	int getWindowHeight()const;

	//displayFunctions
	void displayModel(int gfxIndex, D3DXVECTOR3 position, float pitch, float yaw, float roll);
	void displaySkyBox(int gfxIndex);
	void displayTerrain(int gfxIndex);
	void calculCamera(D3DXVECTOR3 position, float pitch, float yaw, float roll);
	void displayText(LPRECT position, D3DCOLOR color, string text);
	void displayTexture(int indexTexture, D3DXVECTOR3 position);

private:
	//constructor/destructor
	CVisualisation(void);
	~CVisualisation(void);
};
#define VIS CVisualisation::getInstance()
#endif
